package com.stationbuilding.fragment.task;

import android.app.Dialog;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ListView;

import com.stationbuilding.R;
import com.stationbuilding.TestData;
import com.stationbuilding.activity.ShowActivity;
import com.stationbuilding.adapter.home.HomeListAdapter;
import com.stationbuilding.adapter.task.TaskListAdapter;
import com.stationbuilding.bean.QuestionBean;
import com.stationbuilding.bean.TaskBean;
import com.stationbuilding.utils.PreferenceHelper;

import java.util.ArrayList;
import java.util.List;

public class TaskFragment extends Fragment {

    private View view;
    private ListView listView;
    private TaskListAdapter taskListAdapter;
    private List<QuestionBean> taskList = new ArrayList<>();

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.fragment_task, container, false);
        initViews();
        initEvents();
        return view;
    }

    private void initViews() {
        listView = (ListView) view.findViewById(R.id.task_list);
        setAdapter();
    }

    private void setAdapter() {
        taskListAdapter = new TaskListAdapter(getActivity(), taskList);
        listView.setAdapter(taskListAdapter);
        // 数据加载
        loadTaskData();
    }

    private void initEvents() {
        // ListView的点击事件
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                startActivity(new Intent(getActivity(), ShowActivity.class));
            }
        });
    }

    private void loadTaskData() {
        taskListAdapter.updateListView(TestData.getQuestionData());
    }
}
